package com.handu.luna.core.domain.promotion;

import java.math.BigDecimal;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.PostLoad;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import com.handu.luna.core.domain.goods.Goods;

@Entity
public class CreditGoodsGoods extends Promotion {
	
	private long creditGoodsId;
	
	private long goodsId;
	
	@Transient
	private Goods goods;
	private int limitNumber;
//	private int creditType;
	@Min(value=1, message="积分上限必须为数字且不能小于1.")
	@Max(value=100000, message="积分不能大于最大值.")
	private int credit;
//	@Min(value=1, message="现金上限必须为数字且不能小于1.")
//	@Max(value=100000, message="现金不能大于最大值.")
	private BigDecimal money;
	private int isExchange;

    @Transient private List<Long> deleteIdList;

    @PostLoad
    private void init() {
        if(this.goodsId != 0L) {
            goods = context.getGoodsRepository().findOne(goodsId);
        }
    }
	
	public int getLimitNumber() {
		return limitNumber;
	}

	public void setLimitNumber(int limitNumber) {
		this.limitNumber = limitNumber;
	}

    public int getCredit() {
        return credit;
    }

    public void setCredit(int credit) {
        this.credit = credit;
    }

    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public int getIsExchange() {
		return isExchange;
	}

	public void setIsExchange(int isExchange) {
		this.isExchange = isExchange;
	}

	public long getCreditGoodsId() {
		return creditGoodsId;
	}

	public void setCreditGoodsId(long creditGoodsId) {
		this.creditGoodsId = creditGoodsId;
	}

	public long getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(long goodsId) {
		this.goodsId = goodsId;
	}

    public List<Long> getDeleteIdList() {
        return deleteIdList;
    }

    public void setDeleteIdList(List<Long> deleteIdList) {
        this.deleteIdList = deleteIdList;
    }

    public Goods getGoods() {
		if(this.goodsId != 0 && goods == null){
			goods = context.getGoodsRepository().findOne(this.goodsId);
		}
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

}
